package com.yuren.codecrushlearn.Q5300;

import java.util.PriorityQueue;

/**
 * Created with Intellij IDEA.
 * Description:
 * TopK问题
 * @author 10204
 * @date 2025-05-18 21:29
 */
public class Q5333 {
    public int findKthSmallest(int[] nums, int k) {
        PriorityQueue<Integer> maxHeap = new PriorityQueue<>((a, b) -> b - a);
        for (int num : nums) {
            maxHeap.offer(num);
            if (maxHeap.size() > k) {
                maxHeap.poll();
            }
        }
        return maxHeap.peek();
    }
}
